using GEM.Application.Common;
using GEM.Application.Contracts.AI;
using GEM.Application.Dto.AI;
using Microsoft.AspNetCore.Mvc;

namespace GEM.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class DeepseekController : ControllerBase
{
    private readonly IAIService _aiService;
    public DeepseekController(IAIService aiService)
    {
        _aiService = aiService;
    }

    /// <summary>
    /// 发送自定义消息给AI
    /// </summary>
    [HttpPost("chat")]
    public async Task<IActionResult> Chat([FromBody] ChatMessageDto chatMessageDto)
    {
        var response = await _aiService.ChatAsync(chatMessageDto.Message);
        return Ok(response);
    }

    [HttpPost("chat-stream")]
    public async Task ChatStream([FromBody] ChatMessageDto chatMessageDto)
    {
        Response.ContentType = "text/event-stream"; // 或 "application/octet-stream"
        await foreach (var chunk in _aiService.ChatStreamAsync(chatMessageDto.Message))
        {
            await Response.WriteAsync(chunk);
            await Response.Body.FlushAsync();
        }
    }

}